home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_054 / miditools / record.c < prev   
C/C++ Source or Header  |  1992-05-06  |  4KB  |  151 lines

  1. /****************************************************************************
  2.   
  3.    Author:  Fred Cassirer
  4.    Date:    January 24, 1987
  5.    
  6.    This program is placed in the public domain, and from what I understand
  7.    that means anyone can do whatever they want with it.   That's fine 
  8.    because they are fairly trivial anyway ...  If you can get someone to pay
  9.    you for them, you must be doing something right.
  10.  
  11.  ****************************************************************************/
  12. #include "stdio.h"
  13. #include "exec/types.h"
  14. #include "libraries/dos.h"
  15. #include "midi.h"
  16.  
  17. extern int getmidi();
  18. extern void initmidi();
  19. extern void cleanup();
  20.  
  21. /*
  22.      Return time in ticks since last call.  For the 1st call the result is
  23.      undefined.
  24. */
  25.  
  26. ULONG duration()
  27. struct DateStamp dstmp;
  28. ULONG curticks,retval;
  29.  
  30. static ULONG lastics;
  31.  
  32.  DateStamp(&dstmp);
  33.  
  34.  curticks = dstmp.ds_Tick + dstmp . ds_Minute * 60 * TICKS_PER_SECOND;
  35.  retval = curticks - lastics;
  36.  lastics = curticks;
  37.  return(retval); /* 60th's of a second */
  38.  
  39. }
  40.  
  41. main()
  42. {
  43.  
  44.  int i=0;
  45.  int midi_status,midi_note,midi_velocity;
  46.  int midi_sysdata,midi_parmno,midi_setting;
  47.  
  48.  initmidi();
  49.  
  50.  GETMIDI(midi_status);
  51.  duration();  /* Toss the 1st duration to the wind */
  52.  
  53.  for(;;) {
  54.  
  55.   switch (midi_status & 0xff0) {
  56.  
  57.    case NON_MIDI_EVENT:
  58.                 cleanup();
  59.                 exit(FALSE);
  60.      
  61.    case NOTE_OFF : 
  62.    case NOTE_ON  : 
  63.                GETMIDI(midi_note);
  64.                do {
  65.                 GETMIDI(midi_velocity);
  66.                 printf("%02x %04lx %02x %02x %02x ",TIMETAG
  67.                                                    ,duration()
  68.                                                    ,midi_status
  69.                                                    ,midi_note
  70.                                                    ,midi_velocity);
  71.  
  72.                 i += 5;
  73.                 GETMIDI(midi_note);
  74.                 if ((i % 20) == 0) printf("\n");
  75.                } while (!(midi_note & 0x80));
  76.  
  77.                midi_status = midi_note;
  78.                break;
  79.  
  80.    case PITCHWHEEL:
  81.    case PARAMETER:
  82.  
  83.                 printf("%02x %04lx %02x ",TIMETAG,duration(),midi_status); 
  84.                 i += 3; if ((i%20) == 0) printf("\n");
  85.                                          
  86.                GETMIDI(midi_parmno);
  87.                do {
  88.  
  89.                 GETMIDI(midi_setting);
  90.                 printf("%02x %02x ",midi_parmno,midi_setting);
  91.                 i += 2;
  92.  
  93.                 GETMIDI(midi_parmno);
  94.                 if ((i % 20) == 0) printf("\n");
  95.  
  96.                } while (!(midi_parmno & 0x80));
  97.  
  98.                midi_status = midi_parmno;
  99.                break;
  100.  
  101.    case SYSTEM_EXCLUSIVE: 
  102.               
  103.                 switch (midi_status) {
  104.  
  105.                 case SYSTEM_EXCLUSIVE: /* Remember we masked off low nibble */
  106.  
  107.                       printf("%02x %04lx %02x ",TIMETAG,duration(),midi_status); 
  108.                       i += 3; if ((i%20) == 0) printf("\n");
  109.                                          
  110.                       do {
  111.                         GETMIDI(midi_sysdata);
  112.                         printf("%02x ",midi_sysdata);
  113.                       } while ( (midi_sysdata != EOX) &&
  114.                                 (midi_sysdata != ACTIVE_SENSING));
  115.  
  116.                 default: GETMIDI(midi_status);
  117.                          break;
  118.  
  119.                  } /* end inner switch */
  120.  
  121.                  break;
  122.  
  123.    case PROGRAM:  /* These two are followed by a single data byte */
  124.    case CHANNEL_PRESSURE:
  125.  
  126.    case KEY_PRESSURE: /* Whereas this is followed by two.  MIDI_DATA next 
  127.                           time around will pick up the slack. */
  128.  
  129.                 printf("%02x %04lx %02x ",TIMETAG,duration(),midi_status); 
  130.                 i += 3; if ((i%20) == 0) printf("\n");
  131.   
  132.                 GETMIDI(midi_sysdata);
  133.                 printf("%02x ",midi_sysdata);
  134.                 GETMIDI(midi_status);
  135.                 break;  
  136.                                        
  137.    case MIDI_DATA: /* Data bytes for any of the above */
  138.    default:
  139.               printf("%02x ",midi_status);
  140.  
  141.               GETMIDI(midi_status);
  142.               break; 
  143.  
  144.    }
  145.  
  146.  }
  147.  
  148. }
  149.   
  150.